package com.eurobcoin.helper;

import java.io.IOException;
import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class SqlSessionFactoryConfigurer {

	private static final String MYBATIS_CONFIG_FILE = "mybatis.xml";
	
	public static SqlSessionFactory configureSqlSessionFactory(String environment) throws IOException {
		
		Reader reader = Resources.getResourceAsReader(MYBATIS_CONFIG_FILE);
		SqlSessionFactory sqlSessionFactory = null;
		
		if(environment == null) {
			sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
		} else {
			sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader, environment);
		}
		
		return sqlSessionFactory;
	}
	
}
